﻿using System;
using System.Collections.Generic;
using System.IO;

public class FileSystem
{
    private string _workDirectory;
    private string _assetsDirectory;
    private string _uiDirectory;
    private ProjectData _project;
    private Dictionary<string, FileMetaData> _files;
    public FileSystem(string path)
    {
        _workDirectory = Path.GetDirectoryName(path);
        _assetsDirectory = Path.Combine(_workDirectory, "资源");
        if (!Directory.Exists(_assetsDirectory))
            Directory.CreateDirectory(_assetsDirectory);
        _uiDirectory = Path.Combine(_workDirectory, "UI");
        if (!Directory.Exists(_uiDirectory))
            Directory.CreateDirectory(_uiDirectory);
        _project = new ProjectData(path);
        _files = new Dictionary<string, FileMetaData>();
    }
    public event EventHandler FileSystemChanged;
    public static FileSystem Current { get; private set; }
    public string WorkDirectory => _workDirectory;
    public string AssetsDirectory => _assetsDirectory;
    public static bool New(string path)
    {
        var workDirectory = Path.GetDirectoryName(path);
        if (!Directory.Exists(workDirectory))
            Directory.CreateDirectory(workDirectory);
        else if (Directory.GetFiles(workDirectory).Length > 0 || Directory.GetDirectories(workDirectory).Length > 0)
            return false;
        Current = new FileSystem(path);
        return true;
    }
    public ProjectData ProjectInfo { get; }
    public static bool Open(string path)
    {
        if (!File.Exists(path))
        {
            Current = new FileSystem(path);
            return true;
        }
        return false;
    }
    public void Refresh()
    {

    }
}